package com.qubuyer.business.home.view;

import android.content.Context;
import android.graphics.Rect;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.SizeUtils;
import com.qubuyer.R;
import com.qubuyer.business.home.adapter.HomeSuperReturnAdapterV2;
import com.qubuyer.repository.entitys.HomeGoodEntity;

import java.util.List;

/**
 * @author Susong
 * @date 创建时间:2019/6/4
 * @description 首页超级返ViewPage
 * & @version
 */
public class HomeSuperReturnViewPageV2 {
    //当前上下文
    private Context mContext;
    private View mView;

    private RecyclerView rv_list;

    private List<HomeGoodEntity> mData;

    private HomeSuperReturnAdapterV2 mAdapter;
    int dp7_5 = SizeUtils.dp2px(3.75f);
    int dp6 = SizeUtils.dp2px(6);

    public HomeSuperReturnViewPageV2(Context mContext, List<HomeGoodEntity> data) {
        this.mContext = mContext;
        this.mData = data;
    }

    public View getView() {
        if (mView == null) {
            mView = LayoutInflater.from(mContext).inflate(R.layout.layout_fragment_home_category_page, null);
            rv_list = mView.findViewById(R.id.rv_list);
            rv_list.setLayoutManager(new GridLayoutManager(mContext, 3));
            rv_list.addItemDecoration(new RecyclerView.ItemDecoration() {
                @Override
                public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
                    int position = parent.getChildAdapterPosition(view);
                    if (position == 0) {
                        outRect.set(dp6, 0, dp7_5, 0);
                        return;
                    }
                    if (position == parent.getAdapter().getItemCount() - 1) {
                        outRect.set(dp7_5, 0, dp6, 0);
                        return;
                    }
                    outRect.set(dp7_5, 0, dp7_5, 0);
                }
            });
            mAdapter = new HomeSuperReturnAdapterV2(mContext, mData);
            rv_list.setAdapter(mAdapter);
        }
        return mView;
    }
}


